<?php

class sfWidgetFormSelectRadioFlickrPhotoset extends sfWidgetFormSelectRadioFlickrPhoto
{
    protected function formatChoices($name, $value, $choices, $attributes)
    {
        $inputs = array();
        foreach ($choices as $photoset)
        {
            $baseAttributes = array(
                'name'  => substr($name, 0, -2),
                'type'  => 'radio',
                'value' => self::escapeOnce($photoset['id']),
                'id'    => $id = $this->generateId($name, self::escapeOnce($photoset['id'])),
            );

            if (strval($photoset['id']) == strval($value === false ? 0 : $value))
            {
                $baseAttributes['checked'] = 'checked';
            }

            $inputs[$id] = array(
                'input' => $this->renderTag('input', array_merge($baseAttributes, $attributes)),
                'label' => $this->renderContentTag('label', $this->renderContentTag('img', '', array('src' => 'http://farm'.$photoset['farm'].'.staticflickr.com/'.$photoset['server'].'/'.$photoset['primary'].'_'.$photoset['secret'].'_q.jpg', 'title' => $photoset['description']['_content'])), array('for' => $id, 'class' => 'thumbnail')).$photoset['description']['_content'],
            );
        }

        return call_user_func($this->getOption('formatter'), $this, $inputs);
    }
}
